package org.xinjiang.tarim.travel.api;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xinjiang.tarim.travel.utils.VerifyUtil;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.OutputStream;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/api/verify")
public class GetVerify {
    @GetMapping("/getCode")
    public void getCode(HttpServletResponse response) throws Exception{
        Map<String, Object> map = VerifyUtil.createImage();
        //将图片输出给浏览器
        System.out.println(map.get("code"));
        BufferedImage image = (BufferedImage) map.get("image");
        response.setContentType("image/png");
        OutputStream os = response.getOutputStream();
        ImageIO.write(image, "png", os);
    }

}
